<template>
	<view class="w-image">
		<view class="placeholder" :style="dynamicStyle" v-if="!loaded">
			<tn-loading mode="circle" :show="true"></tn-loading>
		</view>
		<image v-show="loaded" :src="src" :style="dynamicStyle" @load="handleLoad" mode=""></image>
	</view>
</template>

<script>
	export default {
		props: {
			src: {
				type: String
			},
			width: {
				type: String
			},
			height: {
				type: String
			},
			radius: {
				type: String
			}
		},
		data() {
			return {
				// #ifdef APP-PLUS || H5
				dynamicStyle: {
					'width': this.width,
					'height': this.height,
					'border-radius': this.radius
				},
				//#endif
				// #ifdef MP
				dynamicStyle:`width:${this.width};height:${this.height};border-radius:${this.radius};`,
				// #endif
				loaded: false
			}
		},
		methods: {
			handleLoad() {
				this.loaded = true
			}
		}
	}
</script>

<style lang="scss" scoped>
	.placeholder {
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #211C37;
	}

	.image {
		animation: identifier 1s;
	}

	@keyframes identifier {
		0% {
			opacity: 0;
		}

		100% {
			opacity: 1;
		}
	}
</style>